capture log close
clear
clear mata
clear matrix
set mem 500m
set more off
graph drop _all
cd "c:\users\james\desktop\dropbox\transparency_and_democracy\transparencydemization\demstability\bjpspublishedversion\replicationfiles\"


#delimit ;

*	************************************************************************ *;
* 	File-Name: TransIrreg.do												 *;
*	Date:  10/09/15															 *;
*	Author: 	James Hollyer                                                *;
*	Purpose:   Replication file assessing the relationship between           *;
*	transparency and irregular leader removal in democracies.				 *;
*	************************************************************************ *;

use "FinalSurvivalData.dta";
drop fail;

stset, clear;

merge 1:m ccode year using "ArchigosPost1980.dta";

*HRV has post 2004 observations, which Archigos does not.  Otherwise, all master;
*data match.;

drop if _merge~=3;
drop _merge;

sort leadid year;

gen irreg_fail=1 if fail==1 & exit==3;
replace irreg_fail=0 if irreg_fail==.;
gen reg_fail=1 if fail==1 & exit==1;
replace reg_fail=0 if reg_fail==.;

stset endobs, id(leadid) fail(irreg_fail==1) origin(eindate) scale(365.25);

stcox lag_transparency lag_growth lag_trans_growth lag_GDP lag_open lag_parl lag_mixed, nohr strata(prior_transition) cluster(leadid);

*The model passes the proportional hazards test.;

estimates store Democracy1;

*The following will generate monte carlo estimates of the effect of a 1 sd;
*change in growth when transparency is high versus when it is low.;

drawnorm b1-b7, means(e(b)) cov(e(V));

sum lag_transparency, detail;

local trans_mean=r(mean)-r(sd);
local trans_high=r(mean)+r(sd);
sum lag_growth, detail;
local growth_mean=r(mean);
local growth_high=r(mean)+r(sd);
sum lag_GDP;
local GDP_mean=r(mean);
sum lag_open;
local open_mean=r(mean);

gen irreg_growth_effect_trans1=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');
gen irreg_growth_effect_not1 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');

gen irreg_diff_effect1 = irreg_growth_effect_trans1 - irreg_growth_effect_not1;

drop b1-b7;

stcox lag_transparency lag_growth lag_trans_growth, nohr strata(prior_transition) 
cluster(leadid);

estimates store Democracy2;

drawnorm b1-b3, means(e(b)) cov(e(V));

gen irreg_growth_effect_trans2=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean');
gen irreg_growth_effect_not2 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean');

gen irreg_diff_effect2 = irreg_growth_effect_trans2 - irreg_growth_effect_not2;

drop b1-b3;

stcox lag_transparency, nohr strata(prior_transition) 
cluster(leadid);

estimates store Democracy3;

stcox lag_transparency lag_growth lag_trans_growth lag_GDP lag_open lag_parl lag_mixed, nohr strata(num_transitions) cluster(leadid);

estimates store Democracy4;

drawnorm b1-b7, means(e(b)) cov(e(V));

gen irreg_growth_effect_trans3=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_high' + b3*`growth_mean' + b3*`trans_high'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');
gen irreg_growth_effect_not3 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_mean' + b3*`growth_mean' + b3*`trans_mean'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');

gen irreg_diff_effect3 = irreg_growth_effect_trans3 - irreg_growth_effect_not3;

drop b1-b7;

stcox lag_transparency lag_growth lag_trans_growth, nohr strata(num_transitions) 
 cluster(leadid);

estimates store Democracy5;

drawnorm b1-b3, means(e(b)) cov(e(V));

gen irreg_growth_effect_trans4=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean');
gen irreg_growth_effect_not4 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean');

gen irreg_diff_effect4 = irreg_growth_effect_trans4 - irreg_growth_effect_not4;

drop b1-b3;

stcox lag_transparency, nohr strata(num_transitions) 
 cluster(leadid);

estimates store Democracy6;

stcox lag_transparency lag_growth lag_trans_growth lag_GDP lag_open lag_parl lag_mixed prior_transition, nohr cluster(leadid);

estimates store Democracy7;

drawnorm b1-b8, means(e(b)) cov(e(V));

gen irreg_growth_effect_trans5=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_high' + b3*`growth_mean' + b3*`trans_high'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');
gen irreg_growth_effect_not5 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_mean' + b3*`growth_mean' + b3*`trans_mean'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');

gen irreg_diff_effect5 = irreg_growth_effect_trans5 - irreg_growth_effect_not5;

drop b1-b8;

stcox lag_transparency lag_growth lag_trans_growth prior_transition, 
nohr cluster(leadid);

estimates store Democracy8;

drawnorm b1-b4, means(e(b)) cov(e(V));

gen irreg_growth_effect_trans6=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean');
gen irreg_growth_effect_not6 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean');

gen irreg_diff_effect6 = irreg_growth_effect_trans6 - irreg_growth_effect_not6;

drop b1-b4;

stcox lag_transparency prior_transition, 
nohr cluster(leadid);

estimates store Democracy9;

sum irreg_diff_effect1, detail;
di r(mean)/r(sd);
sum irreg_diff_effect2, detail;
di r(mean)/r(sd);
sum irreg_diff_effect3, detail;
di r(mean)/r(sd);
sum irreg_diff_effect4, detail;
di r(mean)/r(sd);
sum irreg_diff_effect5, detail;
di r(mean)/r(sd);
sum irreg_diff_effect6, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_trans1, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_not1, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_trans2, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_not2, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_trans3, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_not3, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_trans4, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_not4, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_trans5, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_not5, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_trans6, detail;
di r(mean)/r(sd);
sum irreg_growth_effect_not6, detail;
di r(mean)/r(sd);

*	************************************************************************ *;
*	The following generates Table 3 in the text.                             *;
*	************************************************************************ *;

*estout Democracy1 Democracy2  Democracy3 Democracy4 Democracy5 Democracy6 Democracy7 Democracy8 Democracy9 
using "ireg_removal.tex",
cells(b(star fmt(3)) ci(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) 
stats(N_clust N_fail, labels("\# of Subjects" "\# of Failures")) style(tex) replace;

stset, clear;

*	************************************************************************ *;
*	The following considers the relationship between transparency and the    *;
*	hazard of regular removal from office.                                   *;
*	************************************************************************ *;

stset endobs, id(leadid) fail(reg_fail==1) origin(eindate) scale(365.25);

stcox lag_transparency lag_growth lag_trans_growth lag_GDP lag_open lag_parl lag_mixed, nohr strata(prior_transition) cluster(leadid);

estimates store RegDemocracy1;

*The following will conduct monte carlo simulations of the estimated change in the;
*hazard rate from a 1 sd change in growth from its mean, both when transparency is;
*high and when it is low.;

drawnorm b1-b7, means(e(b)) cov(e(V));

sum lag_transparency, detail;
local trans_mean=r(mean)-r(sd);
local trans_high=r(mean)+r(sd);
sum lag_growth, detail;
local growth_mean=r(mean);
local growth_high=r(mean)+r(sd);
sum lag_GDP;
local GDP_mean=r(mean);
sum lag_open;
local open_mean=r(mean);

gen growth_effect_trans1=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');
gen growth_effect_not1 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');

gen diff_effect1 = growth_effect_trans1 - growth_effect_not1;

drop b1-b7;

*The model passes the proportional hazards test.;


stcox lag_transparency lag_growth lag_trans_growth, nohr strata(prior_transition) 
cluster(leadid);

estimates store RegDemocracy2;

drawnorm b1-b3, means(e(b)) cov(e(V));

gen growth_effect_trans2=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean');
gen growth_effect_not2 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean');

gen diff_effect2 = growth_effect_trans2 - growth_effect_not2;

drop b1-b3;

stcox lag_transparency, nohr strata(prior_transition) 
cluster(leadid);

estimates store RegDemocracy3;

stcox lag_transparency lag_growth lag_trans_growth lag_GDP lag_open lag_parl lag_mixed, nohr strata(num_transitions) cluster(leadid);

estimates store RegDemocracy4;

drawnorm b1-b7, means(e(b)) cov(e(V));

gen growth_effect_trans3=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');
gen growth_effect_not3 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');

gen diff_effect3 = growth_effect_trans3 - growth_effect_not3;

drop b1-b7;

stcox lag_transparency lag_growth lag_trans_growth, nohr strata(num_transitions) 
 cluster(leadid);

estimates store RegDemocracy5;

drawnorm b1-b3, means(e(b)) cov(e(V));

gen growth_effect_trans4=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean');
gen growth_effect_not4 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean');

gen diff_effect4 = growth_effect_trans4 - growth_effect_not4;

drop b1-b3;

stcox lag_transparency, nohr strata(num_transitions) 
 cluster(leadid);

estimates store RegDemocracy6;

stcox lag_transparency lag_growth lag_trans_growth lag_GDP lag_open lag_parl lag_mixed prior_transition, nohr cluster(leadid);

estimates store RegDemocracy7;

drawnorm b1-b8, means(e(b)) cov(e(V));

gen growth_effect_trans5=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');
gen growth_effect_not5 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high'+ b4*`GDP_mean' + b5*`open_mean') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean'+ b4*`GDP_mean' + b5*`open_mean');

gen diff_effect5 = growth_effect_trans5 - growth_effect_not5;

drop b1-b8;

stcox lag_transparency lag_growth lag_trans_growth prior_transition, 
nohr cluster(leadid);

estimates store RegDemocracy8;



drawnorm b1-b4, means(e(b)) cov(e(V));

gen growth_effect_trans6=exp(b1*`trans_high' + b2*`growth_high' + b3*`trans_high'*`growth_high') - 
exp(b1*`trans_high' + b2*`growth_mean' + b3*`trans_high'*`growth_mean');
gen growth_effect_not6 = exp(b1*`trans_mean' + b2*`growth_high' + b3*`trans_mean'*`growth_high') - 
exp(b1*`trans_mean' + b2*`growth_mean' + b3*`trans_mean'*`growth_mean');

gen diff_effect6 = growth_effect_trans6 - growth_effect_not6;

drop b1-b4;

stcox lag_transparency prior_transition, 
nohr cluster(leadid);

estimates store RegDemocracy9;

*	************************************************************************ *;
*	The following generates Table 4 in the text. 							 *;
*	************************************************************************ *;

*estout RegDemocracy1 RegDemocracy2  RegDemocracy3 RegDemocracy4 RegDemocracy5 RegDemocracy6 RegDemocracy7 RegDemocracy8 RegDemocracy9
using "c:\users\james\desktop\dropbox\transparency_and_democracy\transparencydemization\DemStability\reg_removal.tex",
cells(b(star fmt(3)) ci(par fmt(3))) starlevels(* 0.10 ** 0.05 *** 0.01) 
stats(N_clust N_fail, labels("\# of Subjects" "\# of Failures")) style(tex) replace;

sum diff_effect1, detail;
di r(mean)/r(sd);
sum diff_effect2, detail;
di r(mean)/r(sd);
sum diff_effect3, detail;
di r(mean)/r(sd);
sum diff_effect4, detail;
di r(mean)/r(sd);
sum diff_effect5, detail;
di r(mean)/r(sd);
sum diff_effect6, detail;
di r(mean)/r(sd);

sum growth_effect_trans1, detail;
di r(mean)/r(sd);
sum growth_effect_not1, detail;
di r(mean)/r(sd);
sum growth_effect_trans2, detail;
di r(mean)/r(sd);
sum growth_effect_not2, detail;
di r(mean)/r(sd);
sum growth_effect_trans3, detail;
di r(mean)/r(sd);
sum growth_effect_not3, detail;
di r(mean)/r(sd);
sum growth_effect_trans4, detail;
di r(mean)/r(sd);
sum growth_effect_not4, detail;
di r(mean)/r(sd);
sum growth_effect_trans5, detail;
di r(mean)/r(sd);
sum growth_effect_not5, detail;
di r(mean)/r(sd);
sum growth_effect_trans6, detail;
di r(mean)/r(sd);
sum growth_effect_not6, detail;
di r(mean)/r(sd);

*The above estimates are used to construct the values in;
*Table 5 of the text.;
